package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.*;
import com.juyu.miliao.api.domain.dto.DynamicReportInfoDTO;
import com.juyu.miliao.api.domain.vo.DynamicDetailInfoVo;
import com.juyu.miliao.api.domain.vo.DynamicInfoVo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuanqicheng
 * @create 2019-21-10:04
 */
@Repository
public class DynamicInfoDao {
    @Autowired
    private SqlSession sqlSession;

    public void addDynamciInfo(DynamicInfo dynamicInfo) {

        sqlSession.insert("addDynamciInfo",dynamicInfo);

    }

    public List<DynamicInfoVo> selectDynamicListPage(Integer startNum, Integer pageSize) {
        Map<String,Object>  map = new HashMap<>(2);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        return sqlSession.selectList("selectDynamicListPage",map);
    }


    public DynamicDetailInfoVo getDynamicInfoById(long dynamicId) {
        return  sqlSession.selectOne("getDynamicInfoById",dynamicId);
    }

    public void saveDynamicGiftInfo(DynamicGiftInfo dynamicGiftInfo) {
        sqlSession.insert("saveDynamicGiftInfo",dynamicGiftInfo);
    }

    public List<DynamicGiftInfo> getDynamicGiftListByDynamicId(long dynamicId) {
        return sqlSession.selectList("getDynamicGiftListByDynamicId",dynamicId);
    }


    public List<DynamicInfoVo> selectDynamicListUserIdPage(long userId, int startNum, Integer pageSize) {
        Map<String,Object>  map = new HashMap<>(2);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        map.put("userId",userId);
        return sqlSession.selectList("selectDynamicListUserIdPage",map);
    }

    public void addDynamicShare(Long dynamicId) {
        sqlSession.insert("addDynamicShare",dynamicId);
    }

    public DynamicShareInfo getDynamicShareByDynamicId(Long dynamicId) {

        return sqlSession.selectOne("getDynamicShareByDynamicId",dynamicId);

    }

    public void updateShareNumber(Long dynamicId) {
        sqlSession.update("updateShareNumber",dynamicId);
    }

    public DynamicReportInfo getReportByDynamicIdAndUserId(DynamicReportInfoDTO obj) {
        return sqlSession.selectOne("getReportByDynamicIdAndUserId",obj);
    }

    public void addDynamicReportInfo(DynamicReportInfo obj) {
        sqlSession.insert("addDynamicReportInfo",obj);
    }

    public List<DynamicInfoVo> selectDynamicListFollowPage(List<Long> followUserList, int startNum, Integer pageSize) {
        Map<String,Object>  map = new HashMap<>(3);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        map.put("list",followUserList);
        return sqlSession.selectList("selectDynamicListFollowPage",map);
    }

    public void deleteDynamicInfo(long dynamicId) {

        sqlSession.update("deleteDynamicInfo",dynamicId);

    }

    public List<Long> getDynamicGiftUserList(long dynamicId) {
        return sqlSession.selectList("getDynamicGiftUserList",dynamicId);
    }

    public DynamicDetailInfoVo getDynamicInfoNotStatusById(long dynamicId) {
        return sqlSession.selectOne("getDynamicInfoNotStatusById",dynamicId);
    }
}
